, @getDateYear int, @getDateMonth int, @returnDate datetime set @getDate =cast (@yourDate as datetime) set @getDateYear =year (@getDate) set @getDateMonth = Month (@getDate) set @returnDate =cast (str (@getDateYear) + '-' +str (@getDateMonth) + ' -01 ' as datetime)-1 return CONVERT (varchar, @returnDate) End
6 below the date of the beginning of this
The first day of the month on which the given date is calculated
The trick is to calculate the
number of time intervals between the current date and "1900-01-01" and then add it to "1900-01-01" to get a special date, a technique that can be used---to calculate many different dates.
DECLARE @
-- Added the weekly times of the month and year of the date!-- Sunday is counted as "last week "! (Note the differences between weekofyear, weekofmonth, myweekofyear, and myweekofmonth)-- Note that the datename value varies depending on the SQL Server language version or date format!-- The test environment is:
Check this diary record
SELECT * FROM Messages WHERE convert (Nvarchar, createdate, MR) = CONVERT (Nvarchar, GETDATE (),) Order by CreateD Ate DESC
SELECT * from table WHERE DateDiff (day, column name , GETDATE ()) =0
Check this year
SELECT Count (*) from Messages WHERE DateDiff (year,createdate,getdate ()) =0
Query this month
SELECT Count (*) from Messages WHERE DateDiff (month,createdate,getdat
SQL statement used to calculate the number of days in the month and quarter of a given date
SQL statement used to calculate the number of days in the month and quarter of a given date
SQL
Calculate the SQL statement of the last day of the last month of the given date.
Calculate the SQL statement of the last day of the last month of the given date.
Calculate the SQL s
') returns a value of 514,592 secondsDateDiff (' d ', ' 2005-07-20 ', ' 2005-7-25 22:56:32 ') returns a value of 5 days3.DatePart (' W ', ' 2005-7-25 22:56:32 ') returns a value of 2 that is Monday (Sunday is 1, Saturday is 7)DatePart (' d ', ' 2005-7-25 22:56:32 ') returns a value of 25, or 25thDatePart (' y ', ' 2005-7-25 22:56:32 ') returns a value of 206 that is the No. 206 Day of the YearDatePart (' yyyy ', ' 2005-7-25 22:56:32 ') returns a value of 2005 that is 2005Examples of application
Calculate the SQL statement of the first day of the last month and the last day of the month of the given date.
Calculate the SQL statement of the first day of the last month and the last day of the
Tags: englishromcopytimegroup by date settings mon language Tags: datepart function SQL used date month year grouping group by group 2013-12-26 15:31 20764 People read reviews (1) Favorite report Category: SQL Server (21) Copyright notice: This article for Bo Master origina
Query the SQL statement declare @ datedatetime; set @ dategetdate () selectdatepart (month, @ date) [monthofyear]; -- returns the int type selectdatename (month, @ date) [monthofyear]; -- returns the varchar selectmonth (@ query the SQL
Well, I've found some content on the Internet, and we've integrated some of the built-in methods of SQL Server The first is the Convert method: https://msdn.microsoft.com/zh-cn/library/ms187928.aspx CONVERT (data_type (length),data_to_be_converted,style) This method is equivalent to formatting the date data into a string output. And then the stuff method: https://msdn.microsoft.com/zh-cn/library/ms188043.as
Tags: Mon sql get Day server TE name date () secondGets the year, month, day, time, minute, and second data for the current date in SQL Server:SELECT GETDATE () as ' current date ',Datename (Year,getdate ()) as ' year ',Datename (
date as an integer value. This section is specified by DatePart. DATEPART (dd, date) is equivalent to day (date) DATEPART (mm, date) equals month (date) DATEPART (yy, date) is equivale
SQL statement for archiving PHP articles by date (month/day)
Select FROM_UNIXTIME (pubtime, '% Y-% M') as pubtime, count (*) as cnt from articles group by FROM_UNIXTIME (pubtime,' % Y-% M ')
PHP articles are archived by date (day) SQL
value of the Fetch fieldSelect DATEPART (mi,createtime) from Life_unite_product--Take the minute value of the Time fieldSelect DATEPART (ss,createtime) from Life_unite_product--takes the seconds value of the Time fieldSelect DATEPART (ms,createtime) from Life_unite_product--take the millisecond value of the Time fieldSelect DATEADD (yy,-1,createtime) from life_unite_product----fetch Time field (year is reduced by 1)Select DATEADD (mm,3,createtime) from life_unite_product----fetch Time field (
Tags: image RDA src technology ack date query end IMAThe main use of SQL functionsDATEDIFF (datepart,startdate,enddate)SQL statement with database table TableA (date field ddate)--Query todaySELECT * from TableA where DateDiff (dd,voucherdate,getdate ()) = 0--Query yesterdaySELECT * from TableA where DateDiff (dd,vouch
Copy CodeThe code is as follows:
Select From_unixtime (pubtime, '%y-%m ') as Pubtime, COUNT (*) as CNT from articles Group by from_unixtime (Pubtime, '%y-%m ')
PHP Articles by date (day) SQL archive
Copy CodeThe code is as follows:
Select From_unixtime (pubtime, '%y-%m-%d ') as Pubtime, COUNT (*) as CNT from articles Group by from_unixtime (Pubtime, '%y-%m -%d ')
Non-timestamp
See Statistical results:Here is the CONVERT function, and here we have to say the CONVERT functionThe CONVERT () function is a general function that converts a date to a new data type.The CONVERT () function can display date/time data in different formats.GrammarCONVERT (data_type (length),data_to_be_converted,style)Data_type (length) The data type to be converted, you can specify the length of the data typ
Select From_unixtime (pubtime, '%y-%m ') as Pubtime, COUNT (*) as CNT from articles Group by from_unixtime (Pubtime, '%y-%m ')
Copy CodePHP Articles by date (day) SQL archive
Select From_unixtime (pubtime, '%y-%m-%d ') as Pubtime, COUNT (*) as CNT from articles Group by from_unixtime (Pubtime, '%y-%m -%d ')
Copy CodeNon-timestamp
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.